﻿#pragma once

class CCrashHandler
{
public:
	CCrashHandler();
	virtual ~CCrashHandler();
	void SetLogFileName(LPCTSTR pszLogFileName);

public:
	static wchar_t ms_szAppVersion[MAX_PATH];

private:
	//entry point where control comes on an unhandled exception
	static LONG WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);

	//where report info is extracted and generated 
	static void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo);

	//Helper functions
	static LPTSTR GetExceptionString(DWORD dwCode);
	static BOOL GetLogicalAddress(PVOID addr, PTSTR szModule, DWORD len,DWORD& section, DWORD& offset);
	static void IntelStackWalk(PCONTEXT pContext);
	static int __cdecl _tprintf(const TCHAR * format, ...);

	//Variables used by the class
	static TCHAR m_szLogFileName[MAX_PATH];
	static LPTOP_LEVEL_EXCEPTION_FILTER m_previousFilter;
	static HANDLE m_hReportFile;
};

extern CCrashHandler g_crashHandler;   //  global instance of class
